﻿// Decompiled with JetBrains decompiler
// Type: LayersParser.Objects.Item
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using LayersParser.Interfaces;
using System.Collections.Generic;
using System.Xml.Linq;


namespace LayersParser.Objects;

public class Item : Common, ISublines
{
  private string _type;
  private string _conditional;
  private string _condParam;
  private string _xmlSpace;
  private string _convertToInt;
  private string _digitsAfterPoint;
  private int boundStart;
  private int boundEnd;

  public Item(string type)
  {
    this._type = type;
    this.Node = new XElement((XName) nameof (Item), (object) new XAttribute((XName) nameof (Type), (object) this._type));
  }

  public Item(XElement xElement)
  {
    this.Node = xElement;
    this._type = this.Node?.Attribute((XName) nameof (Type))?.Value;
    this._digitsAfterPoint = this.Node?.Attribute((XName) nameof (DigitsAfterPoint))?.Value;
    this._convertToInt = this.Node?.Attribute((XName) nameof (ConvertToInt))?.Value;
    this._xmlSpace = this.Node?.Attribute(XNamespace.Xml + "space")?.Value;
    this._condParam = this.Node?.Attribute((XName) nameof (CondParam))?.Value;
    this._conditional = this.Node?.Attribute((XName) nameof (Conditional))?.Value;
  }

  public string DigitsAfterPoint
  {
    get => this._digitsAfterPoint;
    set
    {
      this._digitsAfterPoint = value;
      this.AddingAttribute((object) this._digitsAfterPoint, nameof (DigitsAfterPoint));
    }
  }

  public string ConvertToInt
  {
    get => this._convertToInt;
    set
    {
      this._convertToInt = value;
      this.AddingAttribute((object) this._convertToInt, nameof (ConvertToInt));
    }
  }

  public string XmlSpace
  {
    get => this._xmlSpace;
    set
    {
      this._xmlSpace = value;
      this.AddingAttribute((object) this._xmlSpace, "xml:space");
    }
  }

  public string CondParam
  {
    get => this._condParam;
    set
    {
      this._condParam = value;
      this.AddingAttribute((object) this._condParam, nameof (CondParam));
    }
  }

  public string Conditional
  {
    get => this._conditional;
    set
    {
      this._conditional = value;
      this.AddingAttribute((object) this._conditional, nameof (Conditional));
    }
  }

  public string Type
  {
    get => this._type;
    set
    {
      this._type = value;
      this.AddingAttribute((object) this._type, nameof (Type));
    }
  }

  private void AddingAttribute(object data, string attribute)
  {
    if (this.Node.Attribute((XName) attribute) != null)
      this.Node.Attribute((XName) attribute).Remove();
    if (data == null)
      return;
    this.Node.Add((object) new XAttribute((XName) attribute, data));
  }

  public string ReturnConditionType() => this._type;

  public string Value
  {
    get => this.Node.Value;
    set => this.Node.Value = value;
  }

  public XElement SublineNode
  {
    get => this.Node;
    set => this.Node = value;
  }

  public List<string> GiveAttributes()
  {
    List<string> stringList = new List<string>();
    if (this._type != null)
      stringList.Add("Type: " + this._type);
    if (this._conditional != null)
      stringList.Add("Conditional: " + this._conditional);
    if (this._condParam != null)
      stringList.Add("CondParam: " + this._condParam);
    if (this._xmlSpace != null)
      stringList.Add("XMLSpace: " + this._xmlSpace);
    if (this._convertToInt != null)
      stringList.Add("ConvertToInt: " + this._convertToInt);
    if (this._digitsAfterPoint != null)
      stringList.Add("DigitsAfterPoint: " + this._condParam);
    return stringList;
  }

  public List<int> Bounds
  {
    get
    {
      return new List<int>()
      {
        this.boundStart,
        this.boundEnd
      };
    }
    set
    {
      this.boundStart = value[0];
      this.boundEnd = value[1];
    }
  }
}
